#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

struct ListNode {
    int val;
    struct ListNode* next;
};

struct ListNode* ReverseList(struct ListNode* pHead) {
    // write code here
    struct ListNode* pre = NULL;
    struct ListNode* cur = pHead;
    struct ListNode* nex = NULL;



    while (cur) {
        nex = cur->next;

        cur->next = pre;
        pre = cur;
        cur = nex;


    }

    return pre;
}
int main()
{
    struct ListNode* pHead = (struct ListNode*)malloc(sizeof(struct ListNode));
    int n = 5;
    pHead->next=NULL;
    struct ListNode* rear = pHead;
    for (int i = 0; i < n; i++)
    {
        struct ListNode*p= (struct ListNode*)malloc(sizeof(struct ListNode));
        scanf("%d", &p->val);
        rear->next = p;
        rear = p;

    }
    rear->next = NULL;
    ReverseList(pHead);


}